/*
*//**
 * Module dependencies.
 *//*

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
*/

var fs = require('fs');
var express = require('express');
var http = require('http');
var ejs = require('ejs');
var mysql = require('mysql');

var app = express();
app.use(app.router);

var client = mysql.createConnection({
	user:'tiger',
	password:'tiger',
	database:'test'
});

/*client.query('select * from products',function(error,result,fields){
	if(error){
		console.log("에러다");
	}else{
		console.log(result);
	}
});*/

http.createServer(app).listen(52273,function(){
	console.log('Server running at http://127.0.0.1:52273');
});

app.get('/',function(request,response){
	fs.readFile('list.html','utf8',function(error,data){
		client.query('select * from products',function(error,results){
			response.send(ejs.render(data,{
				data:results
			}));
		});
	});
});
app.get('/delete/:id',function(request,response){
	client.query('delete from products where id=?',[request.param('id')],function(){
		response.redirect('/');
	});
});
app.get('/insert',function(request,response){
	fs.readFile('insert.html','utf8',function(error,data){
		response.send(data);
	});
});
/*dkdkdkdkdk*//*ffffff*//*ffff*/
app.post('insert',function(request,response){
	var body = request.body;
	console.log(body);
	client.query('insert into products (name, modelnumber,series) values (?,?,?)',
			[body.name,body.modelnumber,body.series],function(){
		response.redirect('/');
	});
});
app.get('/edit/:id',function(request,response){
	
});
app.post('/edit:id',function(request,response){
	
});